package 日期算法.一周中的第几天;

/**
 * TODO
 *
 * @className: yzzddjt
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-05 18:18
 **/
public class yzzddjt {
    public static void main(String[] args) {
//        dayOfTheWeek(31,8,2019);
        dayOfTheWeek(25,1,2013);
    }

    public static String dayOfTheWeek(int day, int month, int year) {
      String[] week = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
      int[] monthDays =  { 0,
              31, 28, 31, 30, 31, 30,
              31, 31, 30, 31, 30, 31
      };
      int days = day - 1;
        for (int i = 1971; i < year; i++) {
            if (isLeapYear(i)){
                days += 366;
            }else {
                days += 365;
            }
        }
        if (month > 1){
            for (int i = 1; i < month; i++) {
                if (isLeapYear(year) && i==2){
                    days += 29;
                    continue;
                }
                days  += monthDays[i];
            }
        }
        int cut = (days) % 7;
        System.out.println( "cut "+cut);
        System.out.println( "days "+(days));
        System.out.println(  week[(cut + 5) % 7  ]);

        return   week[(cut + 5) % 7];

    }
    static boolean isLeapYear(int y) {
        return (y % 4 == 0 && y % 100 != 0|| y % 400 == 0);
    }
}
